package com.sitech.portal.system.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.sitech.ibnms.core.IPage;
import com.sitech.ibnms.core.PageForm;
import com.sitech.ibnms.util.DesEncrypterIsmp;
import com.sitech.portal.system.dao.ISysLogInmsgDao;
import com.sitech.portal.system.domain.TblSYS_LOGINMSG;
import com.sitech.portal.system.form.UserForm;
import com.sitech.portal.system.service.ISysLogInmsgService;
import com.sitech.util.password.BASE64Encoder;
import com.sitech.util.password.PasswordEncoder;

public class SysLogInmsgServiceImpl implements ISysLogInmsgService {

	private ISysLogInmsgDao sysLogInmsgDao;
	
	public ISysLogInmsgDao getSysLogInmsgDao() {
		return sysLogInmsgDao;
	}

	public void setSysLogInmsgDao(ISysLogInmsgDao sysLogInmsgDao) {
		this.sysLogInmsgDao = sysLogInmsgDao;
	}

	@Override
	public void add(TblSYS_LOGINMSG tblSYS_LOGINMSG) {
		// TODO Auto-generated method stub
		sysLogInmsgDao.add(tblSYS_LOGINMSG);
	}

	@Override
	public void cancelfrozen(String[] id) {
		// TODO Auto-generated method stub
		sysLogInmsgDao.cancelfrozen(id);
	}

	@Override
	public void delete(String[] id) {
		// TODO Auto-generated method stub
		sysLogInmsgDao.delete(id);
	}

	@Override
	public TblSYS_LOGINMSG findByUserCode(String userCode) {
		// TODO Auto-generated method stub
		return sysLogInmsgDao.findByUserCode(userCode);
	}
	
	@Override
	public boolean changePasswordByUser(String userCode,String password) {
		DesEncrypterIsmp encrypter = new DesEncrypterIsmp();
		HashMap<String,String> map = new HashMap<String,String>();
		map.put("userNewPassword", encrypter.encrypt(password));
		map.put("userId", userCode);
		sysLogInmsgDao.findByUserCode(userCode);
		updatePassword(map);
		return true;
	}

	@Override
	public IPage findFrozenList(HashMap map,PageForm pageForm) {
		// TODO Auto-generated method stub
		return sysLogInmsgDao.findFrozenList(map,pageForm);
	}

	@Override
	public IPage findListByDeparyType(String depart_type, String mid,
			PageForm pageForm) {
		// TODO Auto-generated method stub
		return sysLogInmsgDao.findListByDeparyType(depart_type, mid, pageForm);
	}

	@Override
	public IPage findListByDeparyTypeAndUnit(String login_id, String userName, String deptId, PageForm pageForm) {
		// TODO Auto-generated method stub
		return sysLogInmsgDao.findListByDeparyTypeAndUnit(login_id, userName, deptId, pageForm);
	}

	@Override
	public IPage findListByDeparyTypeAndUnit(String login_id, String userName, String loginPhone, String deptId, PageForm pageForm) {
		return sysLogInmsgDao.findListByDeparyTypeAndUnit(login_id, userName, loginPhone, deptId, pageForm);
	}

	@Override
	public List findListByMap(Map obj) {
		// TODO Auto-generated method stub
		return sysLogInmsgDao.findListByMap(obj);
	}

	@Override
	public IPage findUnfrozenList(HashMap map,PageForm pageForm) {
		// TODO Auto-generated method stub
		return sysLogInmsgDao.findUnfrozenList(map,pageForm);
	}

	@Override
	public List findUserAll() {
		// TODO Auto-generated method stub
		return sysLogInmsgDao.findUserAll();
	}

	@Override
	public List<HashMap> findUserByDepartId(String deptId) {
		// TODO Auto-generated method stub
		return sysLogInmsgDao.findUserByDepartId(deptId);
	}

	@Override
	public IPage findUserCodeLike(String usercode, String name, PageForm pageForm) {
		// TODO Auto-generated method stub
		return sysLogInmsgDao.findUserCodeLike(usercode, name, pageForm);
	}

	@Override
	public TblSYS_LOGINMSG findUserRoleByPk(String userId) {
		// TODO Auto-generated method stub
		return sysLogInmsgDao.findUserRoleByPk(userId);
	}

	@Override
	public HashMap findUserinfo(String userCode) {
		// TODO Auto-generated method stub
		return sysLogInmsgDao.findUserinfo(userCode);
	}

	@Override
	public HashMap findUserinfoNoManageUnit(String userCode) {
		// TODO Auto-generated method stub
		return sysLogInmsgDao.findUserinfoNoManageUnit(userCode);
	}

	@Override
	public void frozenUser(String[] id) {
		// TODO Auto-generated method stub
		sysLogInmsgDao.frozenUser(id);
	}

	@Override
	public int getCount(String condition) {
		// TODO Auto-generated method stub
		return sysLogInmsgDao.getCount(condition);
	}

	@Override
	public int getCountModule(HashMap a) {
		// TODO Auto-generated method stub
		return sysLogInmsgDao.getCountModule(a);
	}

	@Override
	public List getNaviParam(List getNaviParam) {
		// TODO Auto-generated method stub
		return sysLogInmsgDao.getNaviParam(getNaviParam);
	}

	@Override
	public List loadLoginTreeList(String WORKGROUP_ID, String flag) {
		// TODO Auto-generated method stub
		return sysLogInmsgDao.loadLoginTreeList(WORKGROUP_ID, flag);
	}

	@Override
	public void modifyTbSysLoginMsg(String userName, UserForm userForm) {
		TblSYS_LOGINMSG userObj = new TblSYS_LOGINMSG();
		String telphone = userForm.getTelphone();
		String localphone = userForm.getLocal_phone();
		String email = userForm.getEmail();
		userObj.setLOGIN_ID(userName);
		userObj.setEMAIL_ADDR(email);
		userObj.setLOGIN_PHONE(telphone);
		userObj.setLOCAL_PHONE(localphone);
		// TODO Auto-generated method stub
		sysLogInmsgDao.modifyTbSysLoginMsg(userObj);
	}

	@Override
	public void update(TblSYS_LOGINMSG tblSYS_LOGINMSG) {
		// TODO Auto-generated method stub
		sysLogInmsgDao.update(tblSYS_LOGINMSG);
	}
	
	public void updateMenuType(TblSYS_LOGINMSG tblSYS_LOGINMSG) {
		sysLogInmsgDao.updateMenuType(tblSYS_LOGINMSG);
	}

	@Override
	public void updatePassword(HashMap a) {
		// TODO Auto-generated method stub
		sysLogInmsgDao.updatePassword(a);
	}

	@Override
	public HashMap validLogin(String userCode, String userPassword,
			int tableCount) throws Exception {
		// TODO Auto-generated method stub
		return sysLogInmsgDao.validLogin(userCode, userPassword, tableCount);
	}

	@Override
	public HashMap validLoginBySSO(String userCode, String userPassword,
			int tableCount) throws Exception {
		// TODO Auto-generated method stub
		return sysLogInmsgDao.validLoginBySSO(userCode, userPassword, tableCount);
	}

	@Override
	public boolean validPassword(String userName, String password) {
		TblSYS_LOGINMSG loginMsg = sysLogInmsgDao.findByUserCode(userName);
		if(loginMsg != null ){
			PasswordEncoder pwdEncoder = new BASE64Encoder();
			String pwdtr = pwdEncoder.decode(loginMsg.LOGIN_PASSWD);
			if(password.equals(pwdtr)){
				return true;
			}
			return false;
		}else{
			return false;
		}
	}

	@Override
	public IPage findListByDeparyTypeAndUnit(String deptId, PageForm pageForm) {
		// TODO Auto-generated method stub
		return this.findListByDeparyTypeAndUnit(null, null, deptId, pageForm);
	}

	@Override
	public IPage selectUserByPage(PageForm pageForm){
		return sysLogInmsgDao.selectUserByPage(pageForm);
	}
	

}
